var pn = 1;
var str = "";
var arr = [];
pullUpAction (pn);
function pullUpAction (pn) {
	load_li(pn);
	pn ++;
}

function load_li(pn) {
	$.ajax({
		type: "get",
		url: "../getTeamDate.json",
		data: {
			aid: "3c2c1673f45c4c7f9f7611006f998fe3",
			ps: "10",
			pn: pn
		},
		dataType: "json",
		success: function(rsp) {
			for (var i = 10 * (pn - 1); i < rsp.list.length; i++) {
				var logUrl = rsp.list[i].icon.split(",")[0];
				var name = rsp.list[i].name.split(",")[0];
				str += '<li><div class="li_left"><span class="teamLog"><img src="' + logUrl +
					'"/></span><a href="###">' + name +
					'</a></div><div class="subState"><input type="checkbox" id="' + rsp.list[i].id +
					'" class="check" checked="checked" value="false"/><label for="' + rsp.list[i].id +
					'" class="labsub"></label></div></li>';
				arr[i] = rsp.list[i].type;
			}
			$(".ullist").html(str);
			changeState();
			myscroll.refresh();
		}
	});
}

function changeState() {
	/* 初始化iscroll */
	/* 解决click延迟   */
	window.addEventListener('load', function() {
		FastClick.attach(document.body);
	}, false);
	
	var oSubState = document.getElementsByClassName("subState");
	var oCheck = document.getElementsByClassName("check");
	var oLabsub = document.getElementsByClassName("labsub");
	
	
	for (var i = 0; i < oCheck.length; i ++) {
		oCheck[i].index = i;
		oCheck[i].value = arr[i];
		if(oCheck[i].value == "true"){
			$(".subState").eq(i).addClass("subBg");
			$(".labsub").eq(i).addClass("labmove");
		}
		
		oCheck[i].onclick = function() {
			if(!this.checked) {
				$(".subState").eq(this.index).addClass("subBg");
				$(".labsub").eq(this.index).addClass("labmove");
			}else {
				$(".subState").eq(this.index).removeClass("subBg");
				$(".labsub").eq(this.index).removeClass("labmove");
			}
		}
	}
}



// 下拉刷新
//function pullDownAction () {
//	setTimeout(function () {	// <-- Simulate network congestion, remove setTimeout from production!
//		var el, li, i;
//		el = document.getElementsByClassName("ullist")[0];
//
//		for (i=0; i<3; i++) {
//			li = document.createElement("li");
//			li.innerText = 'Generated row ' + (++generatedCount);
//			el.insertBefore(li);
//		}
//		
//		myScroll.refresh();		//数据加载完成后，调用界面更新方法   Remember to refresh when contents are loaded (ie: on ajax completion)
//	}, 1000);	// <-- Simulate network congestion, remove setTimeout from production!
//}


// 上拉加载
//function pullUpAction () {
//	setTimeout(function () {	// <-- Simulate network congestion, remove setTimeout from production!
//		var el, li, i;
//		el = document.getElementsByClassName("ullist")[0];
//
//		for (i=0; i<3; i++) {
//			li = document.createElement('li');
//			li.innerText = 'Generated row ' + (++generatedCount);
//			el.appendChild(li);
//		}
//		
//		myscroll.refresh();		// 数据加载完成后，调用界面更新方法 Remember to refresh when contents are loaded (ie: on ajax completion)
//	}, 1000);	// <-- Simulate network congestion, remove setTimeout from production!
//}


